package com.dog.basics.admin.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.mtkj.GoodFromDto;
import com.dog.basics.bean.vo.admin.mtkj.GoodFromVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.mtkj.IMtGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@Api(value = "商品管理模块", tags = "商品管理模块")
@RestController
@RequestMapping("/admin/goods")
@AllArgsConstructor
public class MtGoodsController {

    private final IMtGoodsService goodsService;

    /**
     * 查询商品列表并进行分页
     *      1.搜索商品 根据名称查询
     *      2.获取店铺商品
     *      3.获取类别商品
     *      4.获取商铺类别商品
     * @param page
     * @param goodFromDto
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "商品列表", notes = "pc:goods:goodspage")
    @GetMapping("/goodspage/{shopId}")
    @ApiImplicitParam(value = "商铺Id", name = "shopId", dataType = "Long", required = true)
    @PreAuthorize("@pms.hasPermission('pc:goods:goodspage')")
    public R<IPage<GoodFromVo>> page(PageParam page, GoodFromDto goodFromDto){
        IPage<GoodFromVo> list = goodsService.adminFindGoodList(page, goodFromDto);
        return R.ok(list);
    }



    /**
     * 删除商品
     * @param id
     * @return
     * @author hangdy
     */
    @SysLog("删除商品")
    @ApiOperation(value = "删除商品", notes = "pc:goods:gooddelete")
    @ApiImplicitParam(value = "商品Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('pc:goods:gooddelete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(goodsService.adminDeleteGood(id));
    }
}
